home *** CD-ROM | disk | FTP | other *** search
- Path: infoserv.rug.ac.be!news
- From: witold.maranda@elis.rug.ac.be (Witold Maranda)
- Newsgroups: comp.lang.c
- Subject: Re: Help with gettng 2 chars into an integer!
- Date: Wed, 17 Jan 1996 17:51:58 GMT
- Organization: University of Ghent
- Message-ID: <4djcvd$hu6@infoserv.rug.ac.be>
- References: <4d2eh1$7pm@usc.edu>
- Reply-To: witold.maranda@elis.rug.ac.be
- NNTP-Posting-Host: therm9.elis.rug.ac.be
- X-Newsreader: Forte Free Agent 1.0.82
-
- wawda@scf.usc.edu (Abu Wawda) wrote:
-
- >I want to put into a 2-byte integer. It seems easy at first, but I can't seem
- >to figure out to do it with the bit-fidling operators (shifting or masking).
-
- > char a,b;
- > int c;
-
- > a = 'A';
- > b = 'B';
- > c = ? /* the first byte in c should contain the value of a, and the
- > second byte should contain the value of b */
-
- Try this
- c=a;
- c=c<<8;
- c=c+b;
- or simply
- c= a<<8 | b;
-
-
-
- Witek
-
-